package com.sk.bilibili.other;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;

import com.previewlibrary.GPreviewBuilder;
import com.sk.bilibili.bean.Member;
import com.sk.bilibili.bean.Note;
import com.sk.bilibili.dto.ZoomImageInfo;
import com.sk.bilibili.view.activity.ImageActivity;

import java.util.ArrayList;
import java.util.List;

public class NoteImageClickHandler {

    private Activity activity;

    public NoteImageClickHandler(Activity activity) {
        this.activity = activity;
    }

    public void handleNoteImageClick(AdapterView<?> parent, Note note, Member member, int pos){
        List<ZoomImageInfo> list=new ArrayList<>();
        String[] urls = note.getUrls();
        for (int i = 0; i < urls.length; i++) {
            View view = parent.getChildAt(i);
            list.add(new ZoomImageInfo(urls[i],toRect(view)));
        }
        Bundle bundle=new Bundle();
        bundle.putSerializable("note",note);
        bundle.putSerializable("member",member);
        GPreviewBuilder.from(activity)//这里放入activity，me是我自己的命名。
                .to(ImageActivity.class,bundle)
                .setData(list)//放入数据集合
                .setCurrentIndex(pos)//放入你需要查看图片的下标（通常我们使用RecyclerView来展示图片，可以在点击item时放入此代码块，这样可以实现点击查看图片的功能，下标就是为了知道当前展示的是哪一张图）
                .setSingleFling(true)//是否在黑屏区域点击返回
                .setDrag(true)//是否禁用图片拖拽返回
                .setType(GPreviewBuilder.IndicatorType.Number)//指示器类型
                .start();//启动
    }

    private Rect toRect(View view) {
        Rect rect = new Rect();
        view.getGlobalVisibleRect(rect);
        return rect;
    }

}